# -*- coding: utf-8 -*-
from sqlHelper import *
import os,json
arr=os.listdir('img/zq/')
lg=sqlHelper.selectAll("select * from team where logo!='' order by id asc")
ng=sqlHelper.selectAll("select * from team where logo='' order by id asc")
fn=json.dumps(arr)
n=0
for la in lg:
    ena=la['en']
#    print "检索"+str(ena)
    for lb in ng:
#----中英文同名匹配--logo
        if (la['cn']==lb['cn'] and la['cn']!=None and la['cn']!='') or (la['en']==lb['en'] and la['en']!=None and la['en']!='') or (la['big']==lb['big'] and la['big']!=None and la['big']!=''):
            print 'id为'+str(lb['id'])+'的名称['+str(lb['cn'])+']与ID为'+str(la['id'])+'的名称['+str(la['cn'])+']相同'
            sqlHelper.update("update team set logo=%s,note=%s where id=%s",(la['logo'],'logo同名匹配',lb['id']))
            n+=1
#----end

#----中英文同名匹配--繁体
#        if ((la['cn']==lb['cn'] and la['cn']!=None and la['cn']!='') or (la['en']==lb['en'] and la['en']!=None and la['en']!='')) and (la['big']=None or la['big']=''):
#            print 'id为'+str(lb['id'])+'的名称['+str(lb['cn'])+']与ID为'+str(la['id'])+'的名称['+str(la['cn'])+']相同'
#            sqlHelper.update("update team set big=%s,note=%s where id=%s",(la['big'],'big同名匹配',lb['id']))
#----end


#----英文模糊匹配--logo
#        arr=lb['en'].split(' ')
#        for i in arr:
#            if len(i)>len(lb)*2/3 and len(i)>len(ena)*2/3 and ena.find(i)!=-1:
#                sqlHelper.update("update team set logo=%s,note=%s where id=%s",(la['logo'],'logo同名匹配',lb['id']))
#                n+=1
#                continue
#----end

print '共有'+str(n)+'类似'
